import pandas as pd
import numpy as np
import os
import plotly.graph_objs as go
import time
import datetime


class N12_0:
    def __init__(self):
        self.df = None
        df = pd.read_excel(r'/Users/user/PycharmProjects/text1/和鲸社区项目/pandas120.xlsx')
        self.df = df
        self.read_fail()

    def read_fail(self):
        df = self.df
        # print(df.head(10))
        df['salary'] = df['salary'].str.replace('k', '')
        df['salary'] = df['salary'].apply(lambda x: int((int(x.split('-')[0]) + int(x.split('-')[-1])) / 2 * 1000))
        # print(df.groupby('education').mean())
        # print(df.groupby('education')['salary'].mean())
        df['createTime'] = df['createTime'].apply(lambda x: x.to_pydatetime().strftime("%m-%d"))  # 转化为时间为日月
        # print(df.head(10))
        # print(df.info())   查看索引、数据类型和内存信息
        # print(df.describe())   查看数值型列的汇总统计
        group_name = ['低', '中', '高']
        bin = [0, 5000, 20000, 50000]
        df['评级'] = pd.cut(df['salary'], bin, labels=group_name)  # 新增一列根据salary将数据分为三组
        df.sort_values(by='salary', inplace=True, ascending=False)  # 按照salary列对数据降序排列
        print(df.loc[32])  # 取出第三十行
        np.median(df['salary'])  # 得到中位数
        # df.salary.plot(kind='hist')  #绘图
        df.drop(columns=['评级'], inplace=True)
        df['test'] = df['createTime'] + df['education']
        df["test1"] = df["salary"].astype(str) + df['education']
        print(df.dtypes)
        a = df[['salary']].apply(lambda x: x.max() - x.min())  # 最大值与最小值的差
        print(a)
        af = pd.concat([df[:1], df[-2:-1]])
        df.set_index("createTime", inplace=True)
        cf = pd.concat([df, af], axis=0)
        cf.isnull().values.any()
        print(cf)


if __name__ == "__main__":
    start = time.time()
    num = N12_0()
    print(f'此程序运营花费了{round(time.time() - start, 2)}秒')
